package com.nuoniu.sibanyun.service.erp.barcode.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nuoniu.sibanyun.entity.erp.barcode.ErpNsInOutDetail;
import com.nuoniu.sibanyun.mapper.erp.barcode.ErpNsInOutDetailMapper;
import com.nuoniu.sibanyun.service.erp.barcode.IErpNsInOutDetailService;
import com.nuoniu.sibanyun.userThread.UserInfo;
import com.nuoniu.sibanyun.userThread.UserThreadLocal;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * ERP 非标准 出入库 明细 服务实现类
 * </p>
 *
 * @author 白强
 * @since 2021-11-30
 */
@Service
public class ErpNsInOutDetailServiceImpl extends ServiceImpl<ErpNsInOutDetailMapper, ErpNsInOutDetail> implements IErpNsInOutDetailService {

    @Override
    public void removeByOrderId(Long orderId) {
        baseMapper.removeByOrderId(orderId);
    }

    @Override
    public List<ErpNsInOutDetail> listByOrderId(Long orderId) {
        UserInfo userInfo = UserThreadLocal.get();
        QueryWrapper<ErpNsInOutDetail>  queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("order_id",orderId);
        queryWrapper.eq("company_id",userInfo.getCompanyId());
        List<ErpNsInOutDetail> list = list(queryWrapper);
        return list;
    }

    @Override
    public ErpNsInOutDetail getByMainIdAndSourceDetailId(Long mainId, Integer sourceDetailId) {
        QueryWrapper<ErpNsInOutDetail> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("order_id",mainId);
        queryWrapper.eq("source_detail_id",sourceDetailId);
        queryWrapper.last("LIMIT 1");
        ErpNsInOutDetail detail = getOne(queryWrapper, false);
        return detail;
    }
}
